﻿using Southern.Common.Cache;
using Southern.Common.ClientResource;
using Southern.Common.Logger;
using Southern.Models.Southern;
using Southern.Models.Southern.Base;
using System.Configuration;

namespace Southern.Common
{
    public class UnityObject
    {
        public static void Register()
        {
            AspectF.Define
                .Do(() =>
                        {

                            Services.RegisterInstance<ICache>(new HttpRequestCacheResolver());//HttpSessionStateCacheResolver());
                            Services.RegisterInstance<ILogger>(new SystemEventLogger("Southern"));
                            string coreUserConnString =
                                ConfigurationManager.ConnectionStrings["CoreUserConnectionString"].ConnectionString;
                            if (string.IsNullOrEmpty(coreUserConnString))
                                throw new System.NullReferenceException("@coreUserConnString cannot be null or empty");

                            Services.RegisterType<IDatabase>(c => new SouthernDatabase(coreUserConnString));
                            Services.RegisterType<IUrlResolver>(c => new ResoureUrlResolver());

                            Services.RegisterType<IUserRepository>(c => new UserRepository(
                                c.Resolve<IDatabase>(),
                                c.Resolve<ICache>())
                                );
                        });
        }
    }
}